package com.book.dao;
import com.book.entity.Borrow;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

public interface BorrowMapper {
    // 查询借阅列表
    @Results({
            @Result(column = "bookId",property = "bookId"),
            @Result(column = "bookName",property = "bookName"),
            @Result(column = "time",property = "time"),
            @Result(column = "studentId",property = "studentId"),
            @Result(column = "studentName",property = "studentName"),
            @Result(column = "back",property = "back")
    })
    @Select("select borrow.id, book_id bookId,books.name bookName,time,student_id studentId,students.name studentName, back from borrow,books,students where student_id=students.id and book_id=books.id;")
    List<Borrow> getBorrowList();

    // 计数借阅记录
    @Select("select count(*) from borrow;")
    Integer countBorrow();

    // 插入借阅记录
    @Insert("insert into borrow(time, book_id, student_id) values (#{localDateTime}, #{bookId}, #{studentId});")
    void insertBorrow(@Param("localDateTime") LocalDateTime localDateTime, @Param("bookId") Integer bookId, @Param("studentId") Integer studentId);

    // 删除借阅记录
    @Delete("delete from borrow where id = #{id};")
    void deleteBorrowById(Integer id);
}